﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using Wyn.PMS.Common.NightAudit;
using Wyn.PMS.Entity.Entities;
using Wyn.PMS.Logic.Business;

namespace Wyn.PMS.Test.Cache
{
    partial class RoomStatusViewTest
    {
        public static void Test(string hotelid)
        {
            CacheMonitor monitor = CacheMonitor.GetInstance();

            DateTime refreshTime = DateTime.Today.AddYears(-1);

            DateTime time = DateTime.Now;

            while ((DateTime.Now-time).Seconds<5)
            {
                KeyValuePair<DateTime, IEnumerable<Room>> roomKeyValue = monitor.GetCacheRooms(refreshTime,hotelid);

                if (roomKeyValue.Value != null)
                {
                    refreshTime = roomKeyValue.Key;

                    var rooms = roomKeyValue.Value;

                    foreach (var room in rooms)
                    {
                        var ra = room.RoomAttribute.FirstOrDefault(r => r.AttributeCode == "RP");

                        var repair = ra != null ? ra.IsValid.ToString() : "false";

                        Console.WriteLine(room.RoomNo + room.RoomName + room.Status +(room.OrderID??string.Empty)
                                          + room.ModifiedTime.ToString(CultureInfo.InvariantCulture) + repair);
                    }

                    Console.WriteLine("本次更新房间总数：{0}", rooms.Count());
                }

                Thread.Sleep(1000);
            }
            
        }

    }
}
